package com.system.borrow.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.system.borrow.R;
import com.system.borrow.utils.ListViewUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * ================================================
 * 作    者：LuCenly(落尘)
 * 版    本：1.0
 * 创建日期：2016/12/17 22:41
 * 描    述：TODO
 * ================================================
 */
public class LookAdapter extends BaseAdapter{
    private Context context;
    private List<LookBean> list = new ArrayList<>();
    private LayoutInflater inflater;

    public LookAdapter(Context context, List<LookBean> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_look,null);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            viewHolder.lv_data = (ListView) convertView.findViewById(R.id.lv_data);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        LookBean lookBean = list.get(position);
        viewHolder.tv_time.setText(lookBean.time);
        LookListAdapter adapter = new LookListAdapter(context,lookBean.dataList);
        viewHolder.lv_data.setAdapter(adapter);
        ListViewUtils.setListViewHeightBasedOnChildren(viewHolder.lv_data);
        return convertView;
    }

    public class ViewHolder{
        TextView tv_time;
        ListView lv_data;
    }
}
